// 抄官方的util.js，改造了一下
var formatNumber = function (n) {
    n = n.toString()
    return n[1] ? n : '0' + n
}
var sub = function (e) {
    return e.substring(0, 10)
}
var formatTime = function (number, format) {
    var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
    var returnArr = [];

    var date = getDate(number);
    returnArr.push(date.getFullYear());
    returnArr.push(formatNumber(date.getMonth() + 1));
    returnArr.push(formatNumber(date.getDate()));

    returnArr.push(formatNumber(date.getHours()));
    returnArr.push(formatNumber(date.getMinutes()));
    returnArr.push(formatNumber(date.getSeconds()));

    returnArr.forEach(function (item, index) {
        format = format.replace(formateArr[index], item);
    })
    return format;
}
var nameChange = function (e) {
    if (e) {
        if (e.length > 3) {
            e = changeStr(e, 0, '*')
            e = changeStr(e, 1, '*')
        } else {
            e = changeStr(e, 0, '*')
        }
    } else {
        e = '无'
    }
    return e
}
var yuan = function (e) {
    return e.substring(0, 1)
}
var personNumberChange = function (e) {
    // 身份证
    if (e) {
        if (e.length == 18) {
            e = e.substring(0, 6) + '********' + e.substring(14, 18)
        } else if (e.length == 15) {
            e = e.substring(0, 4) + '********' + e.substring(11, 15)
        } else if (e.length >= 4 && e.length != 15 && e.length != 18) {
            e = e.substring(0, 4) + '****'
        }
    }
    return e
}
var changeStr = function (str, index, changeStr) {
    return str.substring(0, index) + changeStr + str.substring(index + changeStr.length);
}
export default {
    yuan: yuan,
    sub: sub,
    formatTime: formatTime,
    nameChange: nameChange,
    personNumberChange: personNumberChange,
};
